<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>all</title>
</head>

<body>
    <script>
        var taskOne = new Promise((resolve, reject) => {
            setTimeout(function () {
                resolve('taskOneFinish')
            }, 1000)
        })

        var taskTwo = new Promise((resolve, reject) => {
            setTimeout(function () {
                reject('taskTwoFinish')
            }, 500)
        })

        var taskThree = new Promise((resolve, reject) => {
            setTimeout(function () {
                reject('taskThreeFinish')
            }, 1500)
        })

        Promise._all = function (promises) {
            let resolveArr = [];
            return new Promise((resolve, reject) => {
                promises.forEach(promise => {
                    promise.then((res) => {
                        resolveArr.push(res)
                        if (resolveArr.length === promises.length) {
                            resolve(resolveArr)
                        }
                    }, (rej) => {
                        reject(rej)
                    })
                });
            })
        }

        Promise._all([taskOne, taskTwo, taskThree]).then((resolve) => {
                console.log(resolve);
            })
            .catch((reject) => {
                console.log(reject);
            })
    </script>
</body>

</html>